<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>分诊管理</title>
    <link rel="stylesheet" href="../../../layui/css/layui.css">
    <link rel="stylesheet" href="../../../css/font-awesome.min.css">
</head>
<body style="background-color:#fff;">

<div class="layui-fluid">
    <!-- 展示分诊记录表需要连接患者 start -->
    <div class="layui-row">
        <table class="layui-hide" id="triageList" lay-filter="triageList"></table>
    </div>
    <!-- 展示分诊记录表需要连接患者 end -->
</div>

<!-- 叫号、诊断按钮 -->
<script type="text/html" id="barDemo">
    {{#  if(d.status ==2||d.status ==1){ }}
    <a class="layui-btn layui-btn-xs layui-btn-disabled">
        叫号&nbsp;
        <i class="fa fa-user-circle"></i>
    </a>
    {{#  }else{ }}
    <a class="layui-btn layui-btn-xs" lay-event="call-patient">
        叫号&nbsp;
        <i class="fa fa-user-circle"></i>
    </a>
    {{#  } }}

    <!-- 打开诊断页面并传入 id -->
    <!--<a href="AddTriage.html?id={{d.id}}" class="layui-btn layui-btn-xs layui-btn-normal" lay-event="diagnose">
        诊断&nbsp;
        <i class="fa fa-medkit"></i>
    </a>-->
    {{#  if(d.status ==2||d.status ==0){ }}
    <a class="layui-btn layui-btn-xs layui-btn-disabled">
        诊断&nbsp;
        <i class="fa fa-user-circle"></i>
    </a>
    {{#  }else{ }}
    <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="diagnose">
        诊断&nbsp;
        <i class="fa fa-user-circle"></i>
    </a>
    {{#  } }}
    <!--诊断form表单-->
    <form class="layui-form layui-form-pane" lay-filter="triageFilter" id="triageForm" style="display: none">
        <div class="layui-form-item">
            <label class="layui-form-label">患者编号</label>
            <div class="layui-input-block">
                <!-- 隐藏文本域 用于存放 id -->
                <input type="hidden" name="tid">
                <input type="hidden" name="patient.pid">
                <input type="text" name="patient.pid" disabled class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">患者姓名</label>
            <div class="layui-input-block">
                <input type="hidden" name="patient.name">
                <input type="text" name="patient.name" disabled class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">科室编号</label>
            <div class="layui-input-block">
                <input type="hidden" name="department.did">
                <input type="text" name="department.did" disabled class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">科室</label>
            <div class="layui-input-block">
                <input type="hidden" name="department.name">
                <input type="text" name="department.name" disabled class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">医生编号</label>
            <div class="layui-input-block">
                <!--<input type="hidden" name="manager.mid">-->
                <input type="text" name="manager.mid" disabled class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">医生姓名</label>
            <div class="layui-input-block">
                <!--<input type="hidden" name="manager.username">-->
                <input type="text" name="manager.username" disabled class="layui-input">
            </div>
        </div>


        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">症状描述</label>
            <div class="layui-input-block">
                    <textarea placeholder="请填写症状描述" class="layui-textarea"
                              name="illness_info"></textarea>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">症状意见</label>
            <div class="layui-input-block">
                    <textarea placeholder="请填写症状意见" class="layui-textarea"
                              name="advice"></textarea>
            </div>
        </div>
        <div class="layui-form-item" style="text-align: center">
            <button class="layui-btn" lay-submit="" lay-filter="add_triage_btn">完成</button>
        </div>
    </form>
</script>
<script src="../../../layui/layui.js"></script>
<script>
    layui.use(['jquery', 'table','layer','form'], function () {
        var $ = layui.jquery; // 注册 jquery 组件
        var table = layui.table;// 注册 table 组件
        var layer = layui.layer;
        var form = layui.form;
        //接收上个页面的数据
        // 只传递一个参数的情况
        // var url = window.location.href;//上个页面的URL地址
        // var did = url.substring(url.lastIndexOf('=') + 1);// 获取诊断记录 did
        //传递多个参数时  location.search获取get请求的参数   获取到的数据，是以?开头的
        //var search = decodeURI(Location.search);//decodeURL是就是内置函数  对其内的URL中的中文解码
        //console.log(search);    //substring(1) 从第二个字符开始截取   ，获取到第二个开始后面所有的字符
        //search = search.substring(1);//s的结果就是上个页面URL后拼接的数据did=xx&name=xx
        var url = decodeURI(window.location.href);
        var search = url.substring(url.lastIndexOf('?') + 1);
        var sarr = search.split("&");    //sarr=[did=xxx,name=xxx]  是上面的字符串s分割后的数组
        var did;//保存科室编号
        var name;//保存科室名称
        for(var i=0;i<sarr.length;i++){
            var data = sarr[i].split("=");//将sarr数组中的数据键值对一一分隔开  【id,xx】
            if(data[0]=='did'){
                did = data[1];
            }else if(data[0]=='name'){
                name = data[1];
            }
        }
        // console.log(did);
        // console.log(name);
        //渲染诊断表格数据
 /*      //渲染诊断表格数据
        table.render({
            elem: '#triageList' //指定原始表格元素选择器（推荐id选择器）
            // 换成真实数据接口时要把 id 传回后台
            , url: '/springboot-hospital/triage/show'
            ,height:340
            ,limit:5
            ,limits:[5,10,15]
            , cols: [[//标题栏
                //colspan即横跨的单元格数，这种情况下不用设置field和width
                {align: 'center', title: '科室患者信息 · 骨科', colspan: 6}
            ]
                , [
                    {field: 'tid', title: '挂号ID', sort: true},
                    {field: 'name', title: '姓名',templet:function (d) {
                            return d.patient.name;
                        }},
                    {field: 'sex', title: '性别',templet:function (d) {
                            if(d.patient.sex == 0){
                                return '女';
                            }else if(d.patient.sex == 1){
                                return '男';
                            }
                        }},
                    {field: 'birth', title: '出生年月日', width: 140,templet:function (d) {
                            return d.patient.birth;
                        }},
                    {
                        field: 'status', title: '状态', width: 130, templet: function (d) {
                            if (d.status == 0) {
                                return '<span style="color: #FF5722">待诊&nbsp;&nbsp;<i class="fa fa-question-circle"></i></span>';
                            } else if (d.status == 1) {
                                return '<span style="color: #337ab7;">诊断中&nbsp;&nbsp;<i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i></span>';
                            } else if (d.status == 2) {
                                return '<span style="color: #5FB878">诊断结束&nbsp;&nbsp;<i class="fa fa-check-circle"></i></span>';

                            }
                        }
                    },
                    {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 320}
                ]] //设置表头
            , page: true //开启分页
            , where:{
                did:did
            }
        });*/
       table.render({
            elem: '#triageList' //指定原始表格元素选择器（推荐id选择器）
            // 换成真实数据接口时要把 id 传回后台
            , url: '/springboot-hospital/triage/show'
            ,limit:3
            ,limits:[3,4,5]
            , cols: [[//标题栏
                //colspan即横跨的单元格数，这种情况下不用设置field和width
                {align: 'center', title: '科室患者信息 · '+name, colspan: 6}
            ]
                , [
                    {field: 'tid', title: '编号', sort: true},
                    {field:'name',title: '姓名',templet:function (t) {
                            return t.patient.name
                        }},
                    {field:'sex',title: '性别',templet:function (t) {
                            if(t.patient.sex==0){
                                return '男'
                            }else{
                                return '女'
                            }
                        }},
                    {field:'sex',title: '出生年月日',templet:function (t) {
                            return t.patient.birth
                        }},
                    {
                        field: 'status', title: '状态', width: 130, templet: function (d) {
                            if (d.status == 0) {
                                return '<span style="color: #FF5722">待诊&nbsp;&nbsp;<i class="fa fa-question-circle"></i></span>';
                            } else if (d.status == 1) {
                                return '<span style="color: #337ab7;">诊断中&nbsp;&nbsp;<i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i></span>';
                            } else if (d.status == 2) {
                                return '<span style="color: #5FB878">诊断结束&nbsp;&nbsp;<i class="fa fa-check-circle"></i></span>';
                            }
                        }
                    },
                    {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 320}
                ]] //设置表头
            , page: true //开启分页
            ,where:{
                did:did
            }
        });
        //call-patient
        //监听行工具事件
        table.on('tool(triageList)', function (obj) {
            var data = obj.data;
            if (obj.event === 'call-patient') {
                // 叫号
                $.ajax({
                    url:'/springboot-hospital/triage/call',
                    data:'tid='+obj.data.tid,
                    success:function (result) {
                        console.log(result);
                        if(result.flag){
                            table.reload('triageList',{
                                where:{
                                    did:result.did
                                }
                            })
                        }
                    }
                })
            }else if(obj.event=='diagnose'){
                //打开诊断页面
                layer.open({
                    type: 1,
                    title: '诊断页面',
                    maxmin: true,
                    shadeClose: true, //点击遮罩关闭层
                    area: ['900px', '520px'],
                    content: $('#triageForm')
                })
                //回显信息
                $.ajax({
                    url:'/springboot-hospital/triage/getOne',
                    data:'tid='+obj.data.tid,
                    success:function (result) {
                        form.val('triageFilter',{
                            tid:result.tid,
                            'patient.pid':result.patient.pid,
                            'patient.name':result.patient.name,
                            'department.did':result.department.did,
                            'department.name':result.department.name,
                            'manager.mid':result.manager.mid,
                            'manager.username':result.manager.username,
                            "illness_info": result.illness_info,
                            "advice": result.advice,
                        })
                    }
                })
                //提交诊断页面数据
                form.on('submit(add_triage_btn)',function (data) {
                    $.ajax({
                        url:'/springboot-hospital/triage/diagnose',
                        data:$('#triageForm').serialize(),//serialize()不能获取form中属性为disabled的输入框的值
                        //data:data.field,    //field可以获取到输入框属性为disabled的值
                        success:function (result) {
                            console.log(result.flag);
                            console.log(result.did);
                            if(result.flag){
                                layer.msg('诊断结束');
                                layer.closeAll();
                                table.reload('triageList',{
                                    where:{
                                        did:result.did
                                    }
                                });
                            }
                        }
                    })
                })
            }
        });
    });
</script>
</body>
</html>